<?php
namespace app\common\controller;
use think\Exception;

/**
 * 节假日类
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/16
 * Time: 11:10
 */
class Holiday{

    /**
     * 处理日期节假日信息
     * @param $year_month
     * @return int
     */
    public function deal_date_holiday($year_month){
        $key = '4e0eef9dc5417ff4afbfd59c9aa746a9';
        $url = 'http://v.juhe.cn/calendar/month?year-month=' . $year_month . '&key=' . $key;
        $holiday_arr = [];
        try{
            $tool = new Tools();
            $r_json = $tool->GetuseCurl($url);
            $r_arr = json_decode($r_json,true);
            if($r_arr['reason'] == 'Success'){
                $holiday_arr = $r_arr['result']['data']['holiday_array'];
                return $holiday_arr;
            }
            return $holiday_arr;
        }catch(Exception $e){
            return 0;
        }
    }

    /**
     * 获取指定日期节假日信息
     * @param $now_date
     * @return mixed
     * 工作日对应结果为 0,
     * 节假日对应结果为 1,
     */
   public function get_date_holiday($now_date){
       $maps = [];
       $maps[] = ['now_date','=',$now_date];
       $h_detail = model('holiday')->get_detail($maps,'id,now_date,holiday');

       $data['now_date'] = $h_detail['now_date'];
       $data['holiday'] = $h_detail['holiday'];
       return $data;
   }
}